$(function(){
	$.get('result.json', function(rtnData){
		console.log(rtnData);
		if(rtnData.code == '200'){
			datas = rtnData.data;
			// 计算每个批次比赛场次
			var batchMap = {};
			$.each(datas, function(index, data) {
				console.log(batchMap[data.batch_id])
				if(batchMap[data.batch_id] == null){
					batchMap[data.batch_id] = 1;
				}else{
					batchMap[data.batch_id] += 1;
				}
			});
			
			// 渲染表格
			var tempBatchId = ''
			$.each(datas, function(index, data) {
				var tdHtml = '<tr>';
				if(tempBatchId != data.batch_id){
					tempBatchId = data.batch_id
					num = batchMap[data.batch_id]
					tdHtml += '<td rowspan="'+num+'">'+data.date+'</td>';
					tdHtml += '<td rowspan="'+num+'">'+data.user_id+'</td>';
					tdHtml += '<td>'+data.match_type+'</td>';
					tdHtml += '<td>'+data.home_name+'</td>';
					tdHtml += '<td>'+data.away_name+'</td>';
					tdHtml += '<td>'+data.win_banker_expect+'/'+data.win_player_expect+'/'+data.win_diff_expect+'</td>';
					tdHtml += '<td>'+data.draw_banker_expect+'/'+data.draw_player_expect+'/'+data.draw_diff_expect+'</td>';
					tdHtml += '<td>'+data.lose_banker_expect+'/'+data.lose_player_expect+'/'+data.lose_diff_expect+'</td>';
					tdHtml += '<td>'+data.win_odds+'/'+data.draw_odds+'/'+data.lose_odds+'</td>';
					tdHtml += '<td>'+data.trade+'/'+data.result+'</td>';
					tdHtml += '<td rowspan="'+num+'">'+data.times+'</td>';
					tdHtml += '<td rowspan="'+num+'">'+data.yield+'</td>';
				}else{
					tdHtml += '<td>'+data.match_type+'</td>';
					tdHtml += '<td>'+data.home_name+'</td>';
					tdHtml += '<td>'+data.away_name+'</td>';
					tdHtml += '<td>'+data.win_banker_expect+'/'+data.win_player_expect+'/'+data.win_diff_expect+'</td>';
					tdHtml += '<td>'+data.draw_banker_expect+'/'+data.draw_player_expect+'/'+data.draw_diff_expect+'</td>';
					tdHtml += '<td>'+data.lose_banker_expect+'/'+data.lose_player_expect+'/'+data.lose_diff_expect+'</td>';
					tdHtml += '<td>'+data.win_odds+'/'+data.draw_odds+'/'+data.lose_odds+'</td>';
					tdHtml += '<td>'+data.trade+'/'+data.result+'</td>';
				}
				tdHtml += '</tr>';
				$('#resultTab').append(tdHtml)
			});
		}
	})
})
